package com.framework.shs.commom.base;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.annotation.JSONField;
import com.framework.shs.a.entity.User;
import com.framework.shs.commom.util.IdGen;
import com.framework.shs.commom.util.UserUtils;
@Entity
public class BaseEntity<T> extends BaseData<T> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6655548040392480474L;

	@Column
	protected String remarks; // 备注
	@Column
	protected String createBy; // 创建者
	@JSONField(format = "yyyy-MM-dd HH:mm:ss")
	// 日期的序列化
	@Column
	@Temporal(value = TemporalType.TIME)
	protected Date createDate; // 创建日期
	@Column
	protected String updateBy; // 更新者
	@JSONField(format = "yyyy-MM-dd HH:mm:ss")
	@Column
	@Temporal(value = TemporalType.TIME)
	protected Date updateDate; // 更新日期
	@Column
	protected String delFlag; // 删除标记（0：正常；1：删除；2：审核）

	@Override
	public void preInsert() {
		// 不限制ID为UUID，调用setIsNewRecord()使用自定义ID
		if (!this.isNewRecord) {
			setId(IdGen.uuid());
		}
		User user = UserUtils.getUser();
		if (StringUtils.isNotBlank(user.getId())) {
			this.updateBy = user.getId();
			this.createBy = user.getId();
		}
		this.updateDate = new Date();
		this.createDate = this.updateDate;

	}

	@Override
	public void preUpdate() {
		User user = UserUtils.getUser();
		if (StringUtils.isNotBlank(user.getId())) {
			this.updateBy = user.getId();
		}
		this.updateDate = new Date();
	}

	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public Date getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}

	public String getDelFlag() {
		return delFlag;
	}

	public void setDelFlag(String delFlag) {
		this.delFlag = delFlag;
	}

	public String getCreateBy() {
		return createBy;
	}

	public void setCreateBy(String createBy) {
		this.createBy = createBy;
	}

	public String getUpdateBy() {
		return updateBy;
	}

	public void setUpdateBy(String updateBy) {
		this.updateBy = updateBy;
	}

}
